using System.Runtime.InteropServices.ComTypes;
using System.Text.Json;
using Microsoft.AspNetCore.Routing.Constraints;
using Zhaoxi.Zhihu.Core;
using Zhaoxi.Zhihu.HttpApi;
using Zhaoxi.Zhihu.Infrastructure;
using Zhaoxi.Zhihu.UseCases;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
//注册基础服务
builder.Services.AddInfrastructureServices(builder.Configuration);

builder.Services.AddUserCaseServices();
builder.Services.AddCoreServices();
//注册WEB服务
builder.Services.AddWebServices();

builder.Services.AddControllers()
    .AddJsonOptions(options =>
    {
        options.JsonSerializerOptions.PropertyNamingPolicy=JsonNamingPolicy.SnakeCaseLower; 
    });
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

builder.Services.AddSwaggerGen();
// 或者使用更简洁的方式只注册需要的约束

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    await app.InitializeDatabaseAsync();
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseCors("AllowAny");
app.UseAuthentication();
app.UseAuthorization();

app.UseExceptionHandler(_ => { });

app.MapControllers();

app.Run();
